<!-- Ndas -->
<div class="main-window-segment" style="padding-top: none; padding-bottom: 20px;">
    <div class="container-fluid">
        <div class="row">

            <div class="col-lg-10 col-md-6 col-sm-12">
                <h2>Rekap RPD Harian per KPPN</h2>
            </div>
			<div class="col-lg-1 col-md-3 col-sm-12" style="padding-top: 20px;">
<?php
                //----------------------------------------------------
                //Development History.Revisi : 0 Kegiatan :1.mencetak hasil filter ke dalam pdf Dibuat oleh : Rifan Abdul Rachman Tanggal dibuat : 18-07-2014  File yang diubah : test.php  
                
						if (isset($this->d_bulan)) {
							$kdbulan = $this->d_bulan;
						} else {
							$kdbulan = 'SEMUA';
						}
						if (isset($this->d_akun)) {
							$kdakun = $this->d_akun;
						} else {
							$kdakun = 'SEMUA';
						}
						if (Session::get('role') == ADMIN || Session::get('role') == PKN || Session::get('role') == KPPN) {
							if (isset($this->d_kanwil)) {
								$kdkanwil = $this->d_kanwil;
							}else{
								$kdkanwil = 'SEMUA';
							}
							if (isset($this->d_kd_kppn)) {
								$kdkppn = $this->d_kd_kppn;
							}else{
								$kdkppn = 'SEMUA';
							}
							if (isset($this->d_kdsatker)) {
								$kdsatker = $this->d_kdsatker;
							}else{
								$kdsatker = 'SEMUA';
							}							
						}
						if (Session::get('role') == SATKER) {
							if (isset($this->d_kdsatker)) {
								$kdsatker = $this->d_kdsatker;
							}else{
								$kdsatker = Session::get('kd_satker');
							}
							if (isset($this->d_kanwil)) {
								$kdkanwil = $this->d_kanwil;
							}else{
								$kdkanwil = 'SEMUA';
							}
							if (isset($this->d_kd_kppn)) {
								$kdkppn = $this->d_kd_kppn;
							}else{
								$kdkppn = 'SEMUA';
							}
						}


						?>
                <div class="btn-group-sm">
                    <button type="button" class="btn btn-default dropdown-toggle fullwidth" data-toggle="dropdown" aria-expanded="false"><span class="glyphicon glyphicon-print"></span>&nbsp; Cetak <span class="caret"></span>
                    </button>
                          <ul class="dropdown-menu" role="menu">
                            <li><a href="<?php echo URL; ?>PDF/rekapRPDMingguKPPN_PDF/<?php echo $kdbulan . "/" . $kdakun . "/" . $kdkanwil . "/" . $kdkppn . "/" . $kdsatker; ?>/PDF">PDF</a></li>
                            <li><a href="<?php echo URL; ?>PDF/rekapRPDMingguKPPN_PDF/<?php echo $kdbulan . "/" . $kdakun . "/" . $kdkanwil . "/" . $kdkppn . "/" . $kdsatker; ?>/XLS">EXCEL</a></li>
                          </ul>
                </div>
						
						<?php
						//----------------------------------------------------		
					
              ?>

			 </div>
			<div class="col-lg-1 col-md-3 col-sm-12" style="padding-top: 20px;">
 			  
                <button type="button" style="width: 100%" class="btn btn-default" data-toggle="modal" data-target="#modal-app-filter"><span class="glyphicon glyphicon-filter"></span> Filter</button>

            </div>
            
        </div>

        <div class="row" style="padding-top: 10px">

            <div class="col-md-6 col-sm-12">
                <?php
                if (isset($this->d_bulan)) {
                    echo "Bulan : ".Tanggal::bulan_indo($this->d_bulan);
                    $kode_bulan = $this->d_bulan;
                } else {
                    $kode_bulan = "SEMUA";
                }
                if (isset($this->d_kanwil)) {
                    foreach ($this->d_nama_kanwil as $kanwil) {
                        echo "<br/>Kanwil : ".$kanwil->get_nama_user() . " (" . substr($kanwil->get_kd_satker(),1,2) . ")";
                        $kode_kanwil = substr($kanwil->get_kd_satker(),1,2);
                    }
                } else {
                    $kode_kanwil = "SEMUA";
                }
                if (isset($this->d_nama_kppn)) {
                    foreach ($this->d_nama_kppn as $kppn) {
                        echo "<br/>".$kppn->get_nama_user() . " (" . $kppn->get_kd_satker() . ")";
                        $kode_kppn = $kppn->get_kd_satker();
                    }
                } else {
                    $kode_kppn = "SEMUA";
                }
                if (isset($this->d_kdsatker)) {
                    echo "<br/>Satker : ".$this->d_kdsatker;
                    $kode_satker = $this->d_kdsatker;
                } else {
                    $kode_satker = "SEMUA";
                }
                if (isset($this->d_akun)) {
                    echo "<br/>Akun : ".$this->d_akun;
                    $kode_akun = $this->d_akun;
                } else {
                    $kode_akun = "SEMUA";
                }
                ?>
            </div>

            <div class="col-md-6 col-sm-12" style="text-align: right;">
                <?php
                echo "<i>(Data dalam jutaan Rupiah)</i>";
                // untuk menampilkan last_update
                if (isset($this->last_update)) {
                    foreach ($this->last_update as $last_update) {
                        echo "Update Data Terakhir (Waktu Server)<br/>" . $last_update->get_last_update() . " WIB";
                    }
                }
                
                ?>
            </div>

        </div>

    </div>
</div>

<!-- Tabel -->
<div id="table-container" class="wrapper">
    <table class="footable">
        <!--baris pertama-->
        <thead>
            <tr>
                <th rowspan = '2'>No.</th>
                <th rowspan = '2'>Kode KPPN</th>
                <th rowspan = '2'>Nama KPPN</th>
                <th colspan = '3'><a href="rekapRPDHariKPPN/<?php echo $kode_bulan ?>/1/<?php echo $kode_kanwil?>/<?php echo $kode_kppn?>/<?php echo $kode_satker?>/<?php echo $kode_akun?>">Minggu 1</a></th>
                <th colspan = '3'><a href="rekapRPDHariKPPN/<?php echo $kode_bulan ?>/2/<?php echo $kode_kanwil?>/<?php echo $kode_kppn?>/<?php echo $kode_satker?>/<?php echo $kode_akun?>">Minggu 2</a></th>
                <th colspan = '3'><a href="rekapRPDHariKPPN/<?php echo $kode_bulan ?>/3/<?php echo $kode_kanwil?>/<?php echo $kode_kppn?>/<?php echo $kode_satker?>/<?php echo $kode_akun?>">Minggu 3</a></th>
                <th colspan = '3'><a href="rekapRPDHariKPPN/<?php echo $kode_bulan ?>/4/<?php echo $kode_kanwil?>/<?php echo $kode_kppn?>/<?php echo $kode_satker?>/<?php echo $kode_akun?>">Minggu 4</a></th>
            </tr>
            <tr>
                <th>RPD</th>
                <th>Realisasi</th>
                <th>Dev(%)</th>
                <th>RPD</th>
                <th>Realisasi</th>
                <th>Dev(%)</th>
                <th>RPD</th>
                <th>Realisasi</th>
                <th>Dev(%)</th>
                <th>RPD</th>
                <th>Realisasi</th>
                <th>Dev(%)</th>
            </tr>
        </thead>
        <tbody class='align-right'>
            <?php
            $no = 1;
            $rpd_3=0;
            $rpd_6=0;
            $rpd_9=0;
            $rpd_12=0;
            if (isset($this->data)) {
                if (empty($this->data)) {
                    echo '<td colspan=12 align="center">Tidak ada data.</td>';
                } else {
                    foreach ($this->data as $value) {
                        $rpd3=$value->get_rpd_3();
                        $rpd6=$value->get_rpd_6();
                        $rpd9=$value->get_rpd_9();
                        $rpd12=$value->get_rpd_12();
                        if($rpd3>100){$rpd3=100;};
                        if($rpd6>100){$rpd6=100;};
                        if($rpd9>100){$rpd9=100;};
                        if($rpd12>100){$rpd12=100;};
                        echo "<tr>	";
                        echo "<td class='align-center'>" . $no++ . "</td>";
                        echo "<td class='align-center'>" . $value->get_kdkppn() . "</td>";
                        echo "<td class='align-left'><a href='rekapRPDSatker/".$kode_bulan."/SEMUA/".$value->get_kdkppn()."'>" . $value->get_nmkppn() . "</a></td>";
                        echo "<td>" . number_format($value->get_rpd_1()) . "</td>";
                        echo "<td>" . number_format($value->get_rpd_2()) . "</td>";
                        echo "<td>" . number_format($rpd3,2,",",".");
                        echo "<td>" . number_format($value->get_rpd_4()) . "</td>";
                        echo "<td>" . number_format($value->get_rpd_5()) . "</td>";
                        echo "<td>" . number_format($rpd6,2,",",".");
                        echo "<td>" . number_format($value->get_rpd_7()) . "</td>";
                        echo "<td>" . number_format($value->get_rpd_8()) . "</td>";
                        echo "<td>" . number_format($rpd9,2,",",".");
                        echo "<td>" . number_format($value->get_rpd_10()) . "</td>";
                        echo "<td>" . number_format($value->get_rpd_11()) . "</td>";
                        echo "<td>" . number_format($rpd12,2,",",".");
                        echo "</tr>	";
                        $rpd_3 += $value->get_rpd_3();
                        $rpd_6 += $value->get_rpd_6();
                        $rpd_9 += $value->get_rpd_9();
                        $rpd_12 += $value->get_rpd_12();                        
                    }
                }
            } else {
                echo '<td colspan=12 align="center" id="filter-first">Silahkan masukkan filter terlebih dahulu.</td>';
            }
            ?>
        </tbody>
        <?php if (isset($this->data)) {
                if (!empty($this->data)) { ?>
        <tfoot>
            <tr class='align-right'>
             
                <td colspan = '3' class='align-center'>Deviasi Rata-Rata</td>
                <td></td>
                <td></td>
                <td>
                    <?php 
                        $total_rpd3=$rpd_3/($no-1); 
                        if ($total_rpd3>100) {$total_rpd3=100;}
                        echo number_format($total_rpd3,2,",",".")
                    ?>
                </td>
                <td></td>
                <td></td>
                <td>
                    <?php 
                        $total_rpd6=$rpd_6/($no-1); 
                        if ($total_rpd6>100) {$total_rpd6=100;}
                        echo number_format($total_rpd6,2,",",".")
                    ?>
                </td>
                <td></td>
                <td></td>
                <td>
                    <?php 
                        $total_rpd9=$rpd_9/($no-1); 
                        if ($total_rpd9>100) {$total_rpd9=100;}
                        echo number_format($total_rpd9,2,",",".")
                    ?>
                </td>
                <td></td>
                <td></td>
                <td>
                    <?php 
                        $total_rpd12=$rpd_12/($no-1); 
                        if ($total_rpd12>100) {$total_rpd12=100;}
                        echo number_format($total_rpd12,2,",",".")
                    ?>
                </td>
            </tr>
        </tfoot>
        <?php } 
            }?>
    </table>
</div>

<!-- Filter -->
<div class="modal fade" id="modal-app-filter" tabindex="-1" role="dialog" aria-labelledby="app-filter-label" aria-hidden="true">

    <div class="modal-dialog">

        <div class="modal-content">

            <div class="modal-header">

                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Tutup</span></button>
                <h4 class="modal-title" id="app-filter-label"><span class="glyphicon glyphicon-filter"></span> Filter Data</h4>

            </div>

            <form id="filter-form" method="POST" action="rekapRPDMingguKPPN" enctype="multipart/form-data">

                <div class="modal-body">

                    <!-- Paste Isi Fom mulai nangkene -->
                    <div>
                        <div>
                        <div id="wbulan" class='alert alert-danger' style='display:none;'></div>
                        <label class="isian">Bulan: </label>
                        <select class="form-control" type="text" name="bulan" id="bulan">
                        <option value='01' <?php if ($this->d_bulan == '01') {
    echo "selected";
} ?> >Januari</option>
                        <option value='02' <?php if ($this->d_bulan == '02') {
    echo "selected";
} ?> >Februari</option>
                        <option value='03' <?php if ($this->d_bulan == '03') {
    echo "selected";
} ?> >Maret</option>
                        <option value='04' <?php if ($this->d_bulan == '04') {
    echo "selected";
} ?> >April</option>
                        <option value='05' <?php if ($this->d_bulan == '05') {
    echo "selected";
} ?> >Mei</option>
                        <option value='06' <?php if ($this->d_bulan == '06') {
    echo "selected";
} ?> >Juni</option>
                        <option value='07' <?php if ($this->d_bulan == '07') {
    echo "selected";
} ?> >Juli</option>
                        <option value='08' <?php if ($this->d_bulan == '08') {
    echo "selected";
} ?> >Agustus</option>
                        <option value='09' <?php if ($this->d_bulan == '09') {
    echo "selected";
} ?> >September</option>
                        <option value='10' <?php if ($this->d_bulan == '10') {
    echo "selected";
} ?> >Oktober</option>
                        <option value='11' <?php if ($this->d_bulan == '11') {
    echo "selected";
} ?> >November</option>
                        <option value='12' <?php if ($this->d_bulan == '12') {
    echo "selected";
} ?> >Desember</option>
                    </select>
                </div>
                    <?php if (isset($this->kanwil_list)) { ?>
                        <br/>
                        <div id="wkdkanwil" class='alert alert-danger' style='display:none;'></div>
                        <label class="isian">Kode Kanwil: </label>
                        <select class="form-control" type="text" name="kdkanwil" id="kdkanwil">
                            <option value='' >-SEMUA KANWIL-</option>
                            <?php
                            foreach ($this->kanwil_list as $value2) {
                                if ($this->d_kanwil == $value2->get_kd_d_kppn()) {
                                    echo "<option value='" . $value2->get_kd_d_kppn() . "' selected>" . $value2->get_kd_d_kppn() . " | " . $value2->get_nama_user() . "</option>";
                                } else {
                                    echo "<option value='" . $value2->get_kd_d_kppn() . "'>" . $value2->get_kd_d_kppn() . " | " . $value2->get_nama_user() . "</option>";
                                }
                            }
                            ?>
                        </select>
                    <?php } ?>
                    <?php if (isset($this->kppn_list)) { ?>
                        <br/>
                        <div id="wkdkppn" class='alert alert-danger' style='display:none;'></div>
                        <label class="isian">Kode KPPN: </label>
                        <select class="form-control" type="text" name="kdkppn" id="kdkppn">
                            <option value='' >-SEMUA KPPN-</option>
                            <?php
                            foreach ($this->kppn_list as $value1) {
                                if ($kode_kppn == $value1->get_kd_d_kppn()) {
                                    echo "<option value='" . $value1->get_kd_d_kppn() . "' selected>" . $value1->get_kd_d_kppn() . " | " . $value1->get_nama_user() . "</option>";
                                } else {
                                    echo "<option value='" . $value1->get_kd_d_kppn() . "'>" . $value1->get_kd_d_kppn() . " | " . $value1->get_nama_user() . "</option>";
                                }
                            }
                            ?>
                        </select>
                    <?php } ?>
                    <?php
                    if (Session::get('role') != SATKER) {
                        echo "<br/>";
                        echo "<div id='wsatker' class='alert alert-danger' style='display:none;'></div>";
                        echo "<label class='isian'>Kode Satker: </label>";
                    }
                    ?>

                    <input class="form-control" type="<?php
                           if (Session::get('role') == SATKER) {
                               echo "hidden";
                           } else {
                               echo "number";
                           }
                           ?>" name="kdsatker" id="kdsatker" size="6" value="<?php
                           if (isset($this->d_kdsatker)) {
                               echo $this->d_kdsatker;
                           }
                           ?>">
                    <br/>
                    <div id="wakun" class="alert alert-danger" style="display:none;"></div>
                    <label class="isian">Akun: </label>
                    <input class="form-control" type="number" name="akun" id="akun" size ="2" value="<?php
                           if (isset($this->d_akun)) {
                               echo $this->d_akun;
                           }
                           ?>">
                </div>
                </div>
                <div class="modal-footer">
                    <button type="submit" name="submit_file" class="btn btn-primary" style="width: 100%" onClick="return cek_upload()">Kirim</button>
                </div>

            </form>

        
        </div>
    </div>

</div>

<!-- Skrip -->
<script type="text/javascript" charset="utf-8">
    $(function() {
        hideErrorId();
        hideWarning();
    });



    function hideErrorId() {
        $('.error').fadeOut(0);
    }

    function hideWarning() {

        $('#nosp2d').keyup(function() {
            if (document.getElementById('nosp2d').value != '') {
                $('#wsp2d').fadeOut(200);
            }
        });

        $('#barsp2d').keyup(function() {
            if (document.getElementById('barsp2d').value != '') {
                $('#wbarsp2d').fadeOut(200);
            }
        });

        $('#kdsatker').keyup(function() {
            if (document.getElementById('kdsatker').value != '') {
                $('#wsatker').fadeOut(200);
            }
        });

        $('#invoice').keyup(function() {
            if (document.getElementById('invoice').value != '') {
                $('#winvoice').fadeOut(200);
            }
        });

        $('#vendor_name').keyup(function() {
            if (document.getElementById('vendor_name').value != '') {
                $('#wvendor_name').fadeOut(200);
            }
        });

        $('#bank').change(function() {
            if (document.getElementById('bank').value != '') {
                $('#wbank').fadeOut(200);
            }
        });

        $('#status').change(function() {
            if (document.getElementById('status').value != '') {
                $('#wstatus').fadeOut(200);
            }
        });

        $('#bayar').change(function() {
            if (document.getElementById('bayar').value != '') {
                $('#wbayar').fadeOut(200);
            }
        });

        $('#tgl_awal').change(function() {
            if (document.getElementById('tgl_awal').value != '' && document.getElementById('tgl_akhir').value != '') {
                $('#wtgl').fadeOut(200);
            }
        });

        $('#tgl_akhir').change(function() {
            if (document.getElementById('tgl_awal').value != '' && document.getElementById('tgl_akhir').value != '') {
                $('#wtgl').fadeOut(200);
            }
        });

    }

    function cek_upload() {

        document.getElementById('invoice').value = document.getElementById('invoice').value.replace(/</g, '').replace(/>/g, '');

        var pattern = '^[0-9]+$';
        var v_nosp2d = document.getElementById('nosp2d').value;
        var v_barsp2d = document.getElementById('barsp2d').value;
        var v_kdsatker = document.getElementById('kdsatker').value;
        var v_invoice = document.getElementById('invoice').value;
        var v_vendor_name = document.getElementById('vendor_name').value;
        var v_bank = document.getElementById('bank').value;
        var v_status = document.getElementById('status').value;
        var v_bayar = document.getElementById('bayar').value;
        var v_tglawal = document.getElementById('tgl_awal').value;
        var v_tglakhir = document.getElementById('tgl_akhir').value;

        var jml = 0;
        if (v_nosp2d == '' && v_barsp2d == '' && v_kdsatker == '' && v_invoice == '' && v_vendor_name == '' && v_bank == '' && v_status == '' && v_bayar == '' && (v_tglawal == '' || v_tglakhir == '')) {
            $('#wsp2d').html('Harap isi salah satu parameter');
            $('#wsp2d').fadeIn();
            jml++;
        }

        if (v_tglawal == '' || v_tglakhir == '') {
            if (v_nosp2d == '' && v_barsp2d == '' && v_invoice == '' && v_vendor_name == '') {
                $('#wsp2d').html('Harap isi salah satu parameter');
                $('#wsp2d').fadeIn();
                $('#wbarsp2d').html('Harap isi salah satu parameter');
                $('#wbarsp2d').fadeIn();
                $('#winvoice').html('Harap isi salah satu parameter');
                $('#winvoice').fadeIn();
                $('#wvendor_name').html('Harap isi salah satu parameter');
                $('#wvendor_name').fadeIn();
                jml++;
            }
        }

        if (v_nosp2d != '' && v_nosp2d.length != 15) {
            $('#wsp2d').html('No. SP2D harus 15 digit');
            $('#wsp2d').fadeIn(200);
            jml++;
        }

        if (v_nosp2d != '' && !v_nosp2d.match(pattern)) {
            var wsp2d = 'No SP2D harus dalam bentuk angka!';
            $('#wsp2d').html(wsp2d);
            $('#wsp2d').fadeIn(200);
            jml++;
        }

        if (v_barsp2d != '' && v_barsp2d.length != 21) {
            $('#wbarsp2d').html('No. Transaksi harus 21 digit');
            $('#wbarsp2d').fadeIn(200);
            jml++;
        }

        if (v_barsp2d != '' && !v_barsp2d.match(pattern)) {
            var wbarsp2d = 'No Transaksi harus dalam bentuk angka!';
            $('#wbarsp2d').html(wbarsp2d);
            $('#wbarsp2d').fadeIn(200);
            jml++;
        }

        if (v_kdsatker != '' && v_kdsatker.length != 6) {
            $('#wsatker').html('Kode Satker harus 6 digit');
            $('#wsatker').fadeIn(200);
            jml++;
        }

        if (v_kdsatker != '' && !v_kdsatker.match(pattern)) {
            var wsatker = 'Kode Satker harus dalam bentuk angka!';
            $('#wsatker').html(wsatker);
            $('#wsatker').fadeIn(200);
            jml++;
        }

        if (v_invoice != '' && v_invoice.length != 18) {
            $('#winvoice').html('No. invoice harus 18 digit');
            $('#winvoice').fadeIn(200);
            jml++;
        }


        if (jml > 0) {
            return false;
        }
    }

</script>
<div class="main-window-segment vertical-padded">
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-12">
                Pertanyaan menu RPD harap menghubungi PIC Direktorat PKN :</br>
                1. Zakaria, HP : 085226950999, email : zacky.469@gmail.com<br>
                2. Tri Angga Sigit, HP : 081410109462, Email : hanif643@gmail.com
            </div>

        </div>
    </div>
</div>